<?php $this->headTitle("Gestion du magasin") ?>
<h4>Gestion du magasin</h4>

<h3>Image du magasin</h3>

<?php if ($this->errors) : ?>
    <div class="well">
        <?php foreach($this->errors as $error) : ?>
            <p class="text-error"><?php echo $error ?></p>
        <?php endforeach ?>
    </div>
<?php endif ?>

<form class="form-horizontal" method="post" action="" enctype="multipart/form-data">
    <div class="control-group">
        <label class="control-label" for="inputText">Texte</label>
        <div class="controls">
            <input required type="text" name="inputText" id="inputText" placeholder="Texte descriptif" value="<?php echo $this->carouselItem['item_text'] ?>">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="inputDateIn">Date de début</label>
        <div class="controls">
            <input required type="text" name="inputDateIn" id="inputDateIn" placeholder="Date de début de validité" value="<?php echo date_format(date_create($this->carouselItem['date_in']), 'd/m/Y') ?>"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="inputDateOut">Date de fin</label>
        <div class="controls">
            <input required type="text" name="inputDateOut" id="inputDateOut" placeholder="Date de fin de validité" value="<?php echo date_format(date_create($this->carouselItem['date_out']), 'd/m/Y') ?>">
        </div>
    </div>
    <?php if ($this->carouselItem['id']) : ?>
    <div class="control-group">
        <label class="control-label" for="imageThumbnail">Aperçu de l'image actuelle</label>
        <div class="controls pointer" id="imageThumbnail">
            <?php $thumbnailPath = Application::getCarouselPicturesPath(true) . 'store/thumbs/' . $this->carouselItem['id'] . '.jpg' ?>
            <?php $imagePath = Application::getCarouselPicturesPath(true) . 'store/' . $this->carouselItem['id'] . '.jpg' ?>
            <img class="img-polaroid" src="<?php echo $thumbnailPath ?>" data-content="<img src='<?php echo $imagePath ?>' />" alt="Image du magasin" title="Aperçu de l'image réele"/>
        </div>
    </div>
    <?php endif ?>
    <div class="control-group">
        <label class="control-label" for="inputFile">Fichier image</label>
        <div class="controls">
            <div class="fileupload fileupload-new" data-provides="fileupload">
                <div class="input-append">
                    <div class="uneditable-input span3">
                        <i class="icon-file fileupload-exists"></i>
                        <span class="fileupload-preview"></span>
                    </div>
                    <span class="btn btn-file">
                        <span class="fileupload-new">Choisir une image</span>
                        <span class="fileupload-exists">Changer</span>
                        <input type="file" <?php if(!$this->carouselItem['id']) : ?>required <?php endif ?>name="inputFile" id="inputFile"/>
                    </span>
                    <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Supprimer</a>
                </div>
            </div>

        </div>
    </div>
    <div class="control-group">
        <button type="submit" name="submit" id="submit_button" class="btn btn-primary">Sauver</button>
        <button type="button" id="reset_button" class="btn">Annuler</button>
    </div>
    <?php echo $this->AuthenticationTokenInput() ?>
</form>

<script language="javascript">
    $(function(){
        $('#inputDateIn').datepicker({
            format: 'dd/mm/yyyy',
            weekStart: 1
        });
        $('#inputDateOut').datepicker({
            format: 'dd/mm/yyyy',
            weekStart: 1
        });
        $('#reset_button').click( function() {
            document.location.href = '/admin-store';
        });
        $('.img-polaroid').popover({
            html: true,
            trigger: 'hover',
            placement: 'right'
        });
    });
</script>

<style>
    /* Give some more space to the labels */
    div.control-group label.control-label {
        width: 175px;
    }

    div.popover {
        max-width: inherit !important;
    }

</style>